package com.bingxu.flink.chapter02.transformation;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

/**
 * @author :BingXu
 * @description :TODO
 * @date :2021/8/9 11:34
 * @modifier :
 */

public class Trans_KeyBy1 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//        env.setParallelism(2);
        DataStreamSource<Integer> sourceDS = env.fromElements(1, 20, 3, 23, 12, 24);
        KeyedStream<Integer, String> keyDS = sourceDS
                .keyBy(ele -> ele % 2 == 0 ? "偶数" : "奇数");
        keyDS.print();

        env.execute();

    }
}
